<?php
/**
 * Custom link when paginator, change from page:{page_number} to ?page={page_number}
 *
 * @author Dat Nguyen <datnt@evolable.asia>
 */
class CustomHtmlHelper extends HtmlHelper {
	/**
	 * Customer link function, unset $url['page'], add $url['?']['page']
	 *
	 * @view HtmlHelper::link()
	 * @param string $title
	 * @param null $url
	 * @param array $options
	 * @param bool $confirmMessage
	 * @return string
	 */
	function link($title, $url = null, $options = array(), $confirmMessage = false) {
		unset($url['direction']);
		foreach ($this->params['url'] as $key => $value) {
			if ($key == 'url' || $key == 'page') {
				continue;
			}
			if (isset($url[$key])) {
				unset($url[$key]);
			}
			$url['?'][$key] = $value;
		}
		if (isset ($url['page'])) {
			$url['?']['page'] = $url['page'];
			unset($url['page']);
		}
		return parent::link($title, $url, $options, $confirmMessage);
	}
}